#include "minunit.h"
#include <lcthw/ringbuffer.h>
#include <assert.h>
#include <string.h>
#include <sys/time.h>

#define BUFFER_LEN 200
static RingBuffer *rbuffer = NULL;

char *test1 = "test1 data";
char *test2 = "test1 data";
char *test3 = "test3 data";
char *test[] = {"test1 data","test2 data","test3 data","test4 data","test5 data","test6 data"};

char *test_create()
{
    rbuffer = RingBuffer_create(BUFFER_LEN);
    mu_assert(rbuffer != NULL, "Failed to create rbuffer.");

    return NULL;
}


char *test_destroy()
{
    RingBuffer_destroy(rbuffer);

    return NULL;

}


char *test_write_read()
{
    char test0[100] = "";    
    RingBuffer_write(rbuffer, test1, strlen(test1));
        RingBuffer_write(rbuffer, test2, strlen(test1));
            RingBuffer_write(rbuffer, test3, strlen(test1));
    RingBuffer_read(rbuffer,test0,strlen(test1));
    printf("str %s len %ld\n",test0,strlen(test0));

    mu_assert(!strcmp(test0 , test1), "Wrong last value.");

    return NULL;
}

char *test_gets()
{
 
    RingBuffer_write(rbuffer, test1, strlen(test1));
    bstring result = RingBuffer_gets(rbuffer, strlen(test1));

    mu_assert(!strcmp((char *)result->data , test1), "Wrong last value.");

    return NULL;
}


char *all_tests() {
    mu_suite_start();

    mu_run_test(test_create);
    mu_run_test(test_write_read);
    mu_run_test(test_gets);

    mu_run_test(test_destroy);


    
    return NULL;
}

RUN_TESTS(all_tests);